package com.my.study.aqs;

import com.my.study.utils.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Semaphore;

/**
 * @author Carlos
 * @version 1.0
 * @Description TODO
 * @date 2021/6/19 19:01
 **/
@Slf4j(topic = "c.TestSemaphore")
public class TestSemaphore {

    public static void main(String[] args) {
        int[] arr;

        int[] arrCopy = new int[2];

        arr = arrCopy.clone();

        System.out.println(arr);
        System.out.println(arrCopy);
    }

    private static void test() {
        Semaphore semaphore = new Semaphore(3);

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                try {
                    semaphore.acquire();
                    log.debug("running...");
                    ThreadUtil.sleep(1);
                    log.debug("end");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    semaphore.release();
                }
            }, "t" + i).start();
        }
    }
}
